/*******************************************************************************
 * Copyright (c) 2005, 2014 springside.github.io
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 *******************************************************************************/
package net.wofly.right.repository;

import java.util.List;

import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.data.repository.query.Param;

import net.wofly.right.domain.FuncList;
import net.wofly.right.domain.RightConfig;
import net.wofly.right.domain.Role;

public interface RightConfigRepository
        extends PagingAndSortingRepository<RightConfig, String>, JpaSpecificationExecutor<RightConfig> {

    @Query("select r from Role r , RightConfig rc where r.roleID = rc.roleID and rc.funcListID = :funcListID")
    List<Role> findRolesByFuncListID(@Param(value = "funcListID") String funcListID);

    @Query("select f from FuncList f , RightConfig rc where f.funcListID = rc.funcListID and rc.rightStatus=1 and rc.roleID = :roleID order by f.funcCode")
    List<FuncList> findFuncListByRoleID(@Param(value = "roleID") String roleID);

    List<RightConfig> findByRoleID(@Param(value = "roleID") String roleID);

    List<RightConfig> findByRoleIDAndFuncListID(String roleID, String funcListID);
}